package com.kcwl.idea.plugins.tool.config;

import com.intellij.openapi.application.Application;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.util.xmlb.XmlSerializerUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;

@State(name = "KcCryptSettings", storages = @Storage("KcCryptSettings.xml"))
public class KcCryptSettings implements PersistentStateComponent<KcCryptSettings> {

    //生产环境配置
    private String mobileKeyPro;
    private String idCardKeyPro;

    //测试环境配置
    private String idCardKeyTest;
    private String mobileKeyTest;

    public static KcCryptSettings getInstance() {
        Application application = ApplicationManager.getApplication();
        return application.getComponent(KcCryptSettings.class);
    }

    public static void storeInstance(@NotNull KcCryptSettings state) {
        getInstance().loadState(state);
    }

    @Nullable
    @Override
    public KcCryptSettings getState() {
        return this;
    }

    @Override
    public void loadState(@NotNull KcCryptSettings state) {
        XmlSerializerUtil.copyBean(state, this);
    }

    public String getMobileKeyPro() {
        return mobileKeyPro;
    }

    public void setMobileKeyPro(String mobileKeyPro) {
        this.mobileKeyPro = mobileKeyPro;
    }

    public String getIdCardKeyPro() {
        return idCardKeyPro;
    }

    public void setIdCardKeyPro(String idCardKeyPro) {
        this.idCardKeyPro = idCardKeyPro;
    }

    public String getIdCardKeyTest() {
        return idCardKeyTest;
    }

    public void setIdCardKeyTest(String idCardKeyTest) {
        this.idCardKeyTest = idCardKeyTest;
    }

    public String getMobileKeyTest() {
        return mobileKeyTest;
    }

    public void setMobileKeyTest(String mobileKeyTest) {
        this.mobileKeyTest = mobileKeyTest;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof KcCryptSettings)) {
            return false;
        }
        KcCryptSettings that = (KcCryptSettings) o;
        if (!Objects.equals(mobileKeyPro, that.mobileKeyPro)) {
            return false;
        }
        if (!Objects.equals(idCardKeyPro, that.idCardKeyPro)) {
            return false;
        }

        if (!Objects.equals(idCardKeyTest, that.idCardKeyTest)) {
            return false;
        }
        if (!Objects.equals(mobileKeyTest, that.mobileKeyTest)) {
            return false;
        }
        return true;
    }
}
